package me.sdevil507.mobile.wxApplet.controller;

import me.sdevil507.mobile.wxApplet.dto.BwechatCheckUserDTO;
import me.sdevil507.mobile.wxApplet.dto.WxCheckUserParamsDTO;
import me.sdevil507.mobile.wxApplet.entity.BwechatCheckUserPO;
import me.sdevil507.mobile.wxApplet.service.WxCheckUserService;
import me.sdevil507.mobile.wxApplet.service.WxWebService;
import me.sdevil507.supports.result.ApiResultDTO;
import me.sdevil507.supports.result.ApiResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/wechatManage")
public class WxManageController {

	@Autowired
	WxWebService wxWebService;

	@Autowired
	WxCheckUserService wxCheckUserService;

	/**
	 * 小程序专家待审核列表查询
	 * @return
	 */
	@PostMapping("/readAllCheckUserByPage")
	public ApiResultDTO readAllCheckUserByPage(@RequestBody WxCheckUserParamsDTO dto) {
		ApiResultDTO apiResultDto;
		try {
			Page<BwechatCheckUserPO> pagePos = wxCheckUserService.readAllByPage(dto.getSearchDto(), dto.getPageDto(), dto.getSortDto());

			apiResultDto = ApiResultGenerator.create("0", "分页数据获取成功!", pagePos);
		} catch (Exception e) {
			apiResultDto = ApiResultGenerator.create("-1", "分页数据获取失败!");
		}
		return apiResultDto;
	}

	/**
	 * 审核
	 * @return
	 */
	@PostMapping("/confirmStatusForWxCheckUser")
	public ApiResultDTO readAllCheckUserByPage(@RequestBody BwechatCheckUserDTO dto) {
		ApiResultDTO apiResultDto;
		try {
			//审核--修改状态
			wxCheckUserService.updateCheckUserData(dto);

			if(("1").equals(dto.getStatus())){
				//审核通过
				wxWebService.buildUserInfo(dto.getRealName(), dto.getPhoneNumber(), dto.getOrgId(), false);
			}
			apiResultDto = ApiResultGenerator.create("0", "审核成功!");
		} catch (Exception e) {
			apiResultDto = ApiResultGenerator.create("-1", "审核失败!");
		}
		return apiResultDto;
	}
}
